<template>
  <!--
    新增或修改对话框：选择生产派工
    -->
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectDone.title" :visible.sync="dialog_selectDone.visible" width="1200px">

    <!-- 检索条件 -->
    <el-form :model="dialog_selectDone.queryParams" :inline="true" v-show="dialog_selectDone.showSearch" label-width="120px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="物料名称" prop="itemName">
            <el-input
              v-model="dialog_selectDone.queryParams.itemName"
              placeholder="请输入物料名称"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="开始日期">
            <el-date-picker
              v-model="dialog_selectDone.queryParams.dtPlanStart"

              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="结束日期" >
            <el-date-picker

              v-model="dialog_selectDone.queryParams.dtPlanDone"
              type=  "daterange"
              range-separator="-"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              start-placeholder="开始时间"
              end-placeholder="结束时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini"
                       @click="getList_dispatch">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>


    <!-- 生产派工列表 -->
    <el-table v-loading="loading" :data="dialog_selectDone.doneList" row-key="dispatchUuid">
      <el-table-column label="汇报时间" align="center" prop="docDt" width="150"/>


      <el-table-column label="汇报号" align="center" prop="docNum" width="150" />

      <el-table-column label="工序类型" align="center" prop="mesDictProcessType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_type" :value="scope.row.mesDictProcessType"/>
        </template>
      </el-table-column>

      <el-table-column label="工序名称" align="center" prop="mesDictProcessName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_name" :value="scope.row.mesDictProcessName"/>
        </template>
      </el-table-column>

      <el-table-column label="工序内容" align="center" prop="processContent" width="120" />

      <el-table-column label="工序符号" align="center" prop="mesDictProcessCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_code" :value="scope.row.mesDictProcessCode"/>
        </template>
      </el-table-column>

      <el-table-column label="物料名称" align="center" prop="itemName" width="180px" :show-overflow-tooltip="true" />

      <el-table-column label="完工数量" align="center" prop="doneQty" />

      <el-table-column label="计量单位" align="center" prop="wmsDictMeasuringUnit" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_dict_measuring_unit" :value="scope.row.wmsDictMeasuringUnit"/>
        </template>
      </el-table-column>

      <el-table-column label="开始日期" align="center" prop="dtStart" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dtStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束日期" align="center" prop="dtDone" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dtDone, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="加工号" align="center" prop="workDocNum" width="160" />
      <el-table-column label="标准定额" align="center" prop="doneQuotaWorkingHours" width="120" />
      <el-table-column label="汇报定额" align="center" prop="totalQuotaWorkingHours" width="120" />
      <el-table-column label="实作时长(分)" align="center" prop="totalWorkingHours" width="120" />

      <el-table-column label="需质检" align="center" prop="sysYesNoQc">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoQc"/>
        </template>
      </el-table-column>


      <el-table-column label="经办人" align="center" prop="attentionUserName" width="150px"/>

      <el-table-column label="审核状态" align="center" prop="oaDictConfirmStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.oa_dict_confirm_status" :value="scope.row.oaDictConfirmStatus"/>
        </template>
      </el-table-column>

      <el-table-column label="请选择" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button type="success" plain
                     size="small"
                     icon="el-icon-check"
                     @click="selectDone_done(scope.row)"
          ><span> 选择</span></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页查询-->
    <pagination
      v-show="dialog_selectDone.total>0"
      :total="dialog_selectDone.total"
      :page.sync="dialog_selectDone.queryParams.pageNum"
      :limit.sync="dialog_selectDone.queryParams.pageSize"
      @pagination="getList_dispatch"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog_hide_selectDone">取 消</el-button>
    </div>

  </el-dialog>

</template>

<script>
  import {listDone} from "@/api/mes/done";
  import { listDept } from "@/api/system/dept";
  import { listUser} from "@/api/system/user";
  export default {
    dicts: [ 'sys_yes_no','mes_dict_process_type','mes_dict_process_name',
      'mes_dict_process_code','sys_normal_disable','wms_dict_measuring_unit'],
    data() {
      return {
        dialog_selectDone: {
          visible: false,
          showSearch: true,
          title: "请选择物料",
          total: 0,
          doneList: [],
          deptList:[],
          masterList:[],
          queryParams:{
            itemName: null,
          }
        },
        //部门下拉
        deptList:[],
        //负责人
        masterList:[],
        // 遮罩层
        loading: true,
        // 遮罩层
        visible: false,
        params_dept:{},
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          roleId: undefined,
          userName: undefined,
          phonenumber: undefined
        },
      };
    },
    created(){
      this.getList_dept()
      this.getList_master()
    },
    methods: {
      /** 列表: 部门（班组） */
      getList_dept(){
        /**班组数据下拉列表查询*/
        this.getConfigKey("workers_group_id").then(response => {
          console.log(response)
          this.params_dept.parentId = response.msg
          listDept(this.params_dept).then(response => {
            console.log(response)
            this.deptList = response.data
          });
        });
      },

      /** 列表: 负责人 */
      getList_master(){
        listUser().then(response => {
          this.masterList = response.rows
        });
      },

      /** 读取列表：生产派工 */
      getList_dispatch() {
        this.loading = true;
        if( this.dialog_selectDone.queryParams.dtPlanStart ){
          this.dialog_selectDone.queryParams.dtPlanStartBegin = this.dialog_selectDone.queryParams.dtPlanStart[0]
          this.dialog_selectDone.queryParams.dtPlanStartEnd = this.dialog_selectDone.queryParams.dtPlanStart[1]
        }else {
          this.dialog_selectDone.queryParams.dtPlanStartBegin = null
          this.dialog_selectDone.queryParams.dtPlanStartEnd = null
        }
        if( this.dialog_selectDone.queryParams.dtPlanDone ){
          this.dialog_selectDone.queryParams.dtPlanDoneBegin = this.dialog_selectDone.queryParams.dtPlanDone[0]
          this.dialog_selectDone.queryParams.dtPlanDoneEnd = this.dialog_selectDone.queryParams.dtPlanDone[1]
        }else {
          this.dialog_selectDone.queryParams.dtPlanDoneBegin = null
          this.dialog_selectDone.queryParams.dtPlanDoneEnd = null
        }
        if( this.dialog_selectDone.queryParams.dtActualStart ){
          this.dialog_selectDone.queryParams.dtActualStartBegin = this.dialog_selectDone.queryParams.dtActualStart[0]
          this.dialog_selectDone.queryParams.dtActualStartEnd = this.dialog_selectDone.queryParams.dtActualStart[1]
        }else {
          this.dialog_selectDone.queryParams.dtActualStartBegin = null
          this.dialog_selectDone.queryParams.dtActualStartEnd = null
        }
        if( this.dialog_selectDone.queryParams.dtActualDone ){
          this.dialog_selectDone.queryParams.dtActualDoneBegin = this.dialog_selectDone.queryParams.dtActualDone[0]
          this.dialog_selectDone.queryParams.dtActualDoneEnd = this.dialog_selectDone.queryParams.dtActualDone[1]
        }else {
          this.dialog_selectDone.queryParams.dtActualDoneBegin = null
          this.dialog_selectDone.queryParams.dtActualDoneEnd = null
        }

        const id = this.$store.state.user.userId
        console.log(id)
        this.dialog_selectDone.queryParams.fkUserIdQc = id
        this.dialog_selectDone.queryParams.sysYesNoQc = 'Y'
        /** 读取列表：生产派工 */
        listDone(this.dialog_selectDone.queryParams).then(response => {
          console.log( response )
          this.dialog_selectDone.doneList = response.rows;
          this.dialog_selectDone.total = response.total;
          this.loading = false;
        });
      },

      /**完成：选择物料*/
      selectDone_done(task) {
        this.dialog_selectDone.visible = false;
        this.$emit("ok", task );
        console.log( task )
      },

      /**对话框：显示 - 选择生产派工*/
      dialog_show_selectDone() {
        this.getList_dispatch()
        this.dialog_selectDone.visible = true;
        this.dialog_selectDone.title = "选择生产派工";
      },

      /**对话框：隐藏 - 选择生产派工*/
      dialog_hide_selectDone() {
        this.dialog_selectDone.visible = false;
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
